package com.breaking.second.entity;


import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;

import java.util.List;

import lombok.Data;

//响应通用
@Data
public class BookEntity {
    private String msg;
    private int code;
    private Object data;

    public boolean isCode() {
        return code == 200;
    }

    public <T> T to(Class<T> c) {
        if (data instanceof JSONObject da) {
            return da.to(c);
        }
        return null;
    }

    public <T> List<T> toList(Class<T> itemClass) {
        if (data instanceof JSONArray da) {
            return da.toList(itemClass);
        }
        return null;
    }
}
